import java.util.Arrays;
import java.util.Stack;

/**
 * Created with Intellij JDEA
 * Description:
 * User:
 * Date:2022-03-20
 * Time:16:16
 */
public class MyStack {
    public int[] elem;
    public int usedSize;

    public MyStack() {
        this.elem = new int[10];
    }

    public void push(int val) {
        if (isFull()) {
            this.elem = Arrays.copyOf(this.elem,2*this.elem.length);
        }
        this.elem[usedSize] = val;
        this.usedSize++;
    }

    public boolean isFull() {
        return this.usedSize == this.elem.length;
    }

    public int pop() {
        if (empty()) {
            throw new RuntimeException("栈为空！");
        }
        this.usedSize--;
        return this.elem[usedSize];
    }

    public int peek() {
        if (empty()) {
            throw new RuntimeException("栈为空！");
        }
        return this.elem[usedSize - 1];
    }
    public boolean empty() {
        return this.usedSize == 0;
    }

    public int size() {
        return this.usedSize;
    }

}
